Hi all,
I am working on a script to take all of the linksets in one link module and move them (along with their corresponding links) to another link module. The script seems to work flawlessly on some attempts, but loses links on others and does not return an error. I think the error could reside in cases where either the linkset already exists in the new link module, or when a linkset is linking a module to itself. However when I create these test cases it runs perfectly, only to run into errors again when I apply it to modules in a project. I would really appreciate if anyone could look over the script to see potential errors, or knows of a working script to dump the linksets from one link module into another.
The script is attached below. View DetailsmovelinksetJohn'sUpdate.dxl
Thanks. JohnEarnshaw - Wed Aug 05 11:32:54 EDT 2015 |
Re: Moving linksets script not working
So you are merging the links of two link modules into one of them.
I'm a little worried when duplicating links when the target object is the same as the source object. The link you create at line #114 becomes part of the loop at line #105. That "should" not matter but it might. You an put the Links from o1 into a skip list, then browse the Skip list; above line #105:
Line #103; not sure about "all", I always use "entire(m1)"; then continue if the object is deleted. Line#168, loading the link set will open up both source/target modules; which I notice you leave open. I do't think you need to load the linkset before deleting it. Line #169 I notice you are not trapping the delete linkset attempt. Line #81, surely you don't need a "flushDeletions" after removing the LMD? Line #80, seems to me you should only attempt to remove and create the LMD if there currently exists one.
Line #100; yes creating a LinkSet when one already exists does't matter.
Line #70: add new elseif(!isEdit(m1)) then -Louie
|
Re: Moving linksets script not working Is it possible you lack full rights to all the m1 objects? Insert a "if (!canModify(o1))" at the top of the object loop. |
Re: Moving linksets script not working llandale - Wed Aug 05 19:36:12 EDT 2015
So you are merging the links of two link modules into one of them.
I'm a little worried when duplicating links when the target object is the same as the source object. The link you create at line #114 becomes part of the loop at line #105. That "should" not matter but it might. You an put the Links from o1 into a skip list, then browse the Skip list; above line #105:
Line #103; not sure about "all", I always use "entire(m1)"; then continue if the object is deleted. Line#168, loading the link set will open up both source/target modules; which I notice you leave open. I do't think you need to load the linkset before deleting it. Line #169 I notice you are not trapping the delete linkset attempt. Line #81, surely you don't need a "flushDeletions" after removing the LMD? Line #80, seems to me you should only attempt to remove and create the LMD if there currently exists one.
Line #100; yes creating a LinkSet when one already exists does't matter.
Line #70: add new elseif(!isEdit(m1)) then -Louie
I really appreciate the feedback, you made some great points and I took it all into consideration while updating my script. I especially like the idea of flushing deletions after removing the LMD just in case there was an obscure overlap. However even with the new and improved script I still ran into the same error as before. The problem I am getting with the script is that before the merge I will use a script to count all the links in Link Module A, as well as all of the links in Link Module B. After running the script to put the links from link module B into A, I will count the links in link module A again. Here I am expecting the output to be the sum of the first two counts, however occasionally I get a result which is slightly less than the desired sum. When I have been able to trace this error down to a specific case, it was because some of the linksets in the new link module were empty and had moved over nothing at all, with no error message from my script. I just ran the script to move 6825 links into a LM with 4667 and got 11489 instead of 11492. I think that means an error in the script still exists, however maybe it is due to an odd anomaly of initially having the same link existing in both link modules. Let me know what you think, I have attached both the update script as well as the script I use to count the links in a Link Module. Attachments Count links in LM (not detailed).dxl movelinksetJohn'sUpdate.dxl |
Re: Moving linksets script not working JohnEarnshaw - Thu Aug 06 13:54:07 EDT 2015 I really appreciate the feedback, you made some great points and I took it all into consideration while updating my script. I especially like the idea of flushing deletions after removing the LMD just in case there was an obscure overlap. However even with the new and improved script I still ran into the same error as before. The problem I am getting with the script is that before the merge I will use a script to count all the links in Link Module A, as well as all of the links in Link Module B. After running the script to put the links from link module B into A, I will count the links in link module A again. Here I am expecting the output to be the sum of the first two counts, however occasionally I get a result which is slightly less than the desired sum. When I have been able to trace this error down to a specific case, it was because some of the linksets in the new link module were empty and had moved over nothing at all, with no error message from my script. I just ran the script to move 6825 links into a LM with 4667 and got 11489 instead of 11492. I think that means an error in the script still exists, however maybe it is due to an odd anomaly of initially having the same link existing in both link modules. Let me know what you think, I have attached both the update script as well as the script I use to count the links in a Link Module. I did also not see an error on your script right away - I think the way to go here, would be to dump all the links, before and after the move and find and compare the results to find out which links are missing. I remember I have done a link dump script in some post, maybe that can help.
(attachment_14846651_linkDump.zip) It will allow you to quickly dump all links to a file and then read them back and count them (e.g. by link module) or dump them sorted to a file, so you will see where exactly you are missing links. You will probably have to modify the code here and there, but it might give you a quick start. Maybe that helps, regards, Mathias |
Re: Moving linksets script not working JohnEarnshaw - Thu Aug 06 13:54:07 EDT 2015 I really appreciate the feedback, you made some great points and I took it all into consideration while updating my script. I especially like the idea of flushing deletions after removing the LMD just in case there was an obscure overlap. However even with the new and improved script I still ran into the same error as before. The problem I am getting with the script is that before the merge I will use a script to count all the links in Link Module A, as well as all of the links in Link Module B. After running the script to put the links from link module B into A, I will count the links in link module A again. Here I am expecting the output to be the sum of the first two counts, however occasionally I get a result which is slightly less than the desired sum. When I have been able to trace this error down to a specific case, it was because some of the linksets in the new link module were empty and had moved over nothing at all, with no error message from my script. I just ran the script to move 6825 links into a LM with 4667 and got 11489 instead of 11492. I think that means an error in the script still exists, however maybe it is due to an odd anomaly of initially having the same link existing in both link modules. Let me know what you think, I have attached both the update script as well as the script I use to count the links in a Link Module. Lazy today, but I have a nagging memory that trying to create a link that already exists produces no link error:
That will be easy for you to check manually; write a 5 line DXL to create a link trapping the error, and then run it twice. If you want your code to check you will need to look for the link in a link loop which I suspect will corrupt your outer for k ub i1 -> lmn do loop; in which case staging those links in a skip list will be required. Alternatively, now that I think of it, you can loop through incoming links to o2. I notice your count script turns filtering off whereas your copy link script does not. Is it possible the default view has a Filter? These are the cases that caused me to almost always use the "entire mod" loop and I'm guaranteed to get all the objects in the exact same order each time. (BTW, your "filtering off" needs "current = sm" before it; just in case). I notice your count script gets "all(o->lmn)" links but your copy script does not. -Louie |
Re: Moving linksets script not working
( Seems that you are not dealing with the baselines ... If i'm not missing something, the posted code should ignore the links to baselines. |
Re: Moving linksets script not working I found this script really helpful. For my peace of mind, I hacked together John and Matthias' fine work into the attached, so that it would always be easy to verify that no links were lost in the process. I humbly submit it to posterity on the condition that I receive full credit for all errors and inelegant code. After running the script, a quick run of your favorite diff tool should verify that the only change is the link module name.
Note that in the course of testing, I was able to produce a corrupt module by, I believe, running the script with one of the source modules open in Shareable Edit. The result was an error message "Unable to parse treedata, Line 2, expected MaxID" or something similar. Simply re-running the script a couple of times to switch the linksets back and forth seems to have recovered the module. I lack the time or skill to fully investigate and fix the issue. I have since ensured that all modules are closed before running the tool and the issue has not recurred. Attachments Move Linksets.dxl |
Re: Moving linksets script not working Mathias Mamsch - Fri Aug 07 11:10:21 EDT 2015 I did also not see an error on your script right away - I think the way to go here, would be to dump all the links, before and after the move and find and compare the results to find out which links are missing. I remember I have done a link dump script in some post, maybe that can help.
(attachment_14846651_linkDump.zip) It will allow you to quickly dump all links to a file and then read them back and count them (e.g. by link module) or dump them sorted to a file, so you will see where exactly you are missing links. You will probably have to modify the code here and there, but it might give you a quick start. Maybe that helps, regards, Mathias Mathias, I've downloaded the attachment_14846651_linkDump.zip file and when I try to open it I get an error saying the file is bad. Can you post the DXL file? Regards, Rich |
Re: Moving linksets script not working RichRif - Fri Mar 23 10:29:43 EDT 2018 Mathias, I've downloaded the attachment_14846651_linkDump.zip file and when I try to open it I get an error saying the file is bad. Can you post the DXL file? Regards, Rich I could download the file perfectly. I have attached the files separately. Hope it helps, regards, Mathias Attachments dumpLinksExample.dxl linkStatistics.dxl |